 function comment() {
     var parentId = $("input[name=parentId]").val();
     var content = $(".comment_textarea").val();
     if (content == null || content.trim() == "") {
        $(".alert-danger").show()
         return;
     }else {
        $(".alert-danger").hide()
     }
     var data = {
         content: content,
         parentId: parentId,
         type: 1
     }
    $.ajax({
        url: "/comment",
        contentType: "application/json",
        type: "POST",
        dataType: "json",
        data: JSON.stringify(data),
        success(response) {
            if (response.code == 200) {
                $(".comment_textarea").val("")
                window.location.reload()
                window.scrollTo(0,0)
            } else {
                if (response.code = 2003) {
                    var isLogin = window.confirm(response.message);
                    if (isLogin) {
                        window.open("https://gitee.com/oauth/authorize?client_id=9cd8e853407fc6a52e6bc99f27e9d530a0c9bd9fcba10fccdd09d48d7c147d52&redirect_uri=http://localhost:8887/callback&scope=user_info&response_type=code");
                        window.localStorage.setItem("closed", true)
                    }

                } else {
                    alter(response.message);
                }
            }
        }
    })
 }

 function commentParent(e) {
     var parentId = e.getAttribute("data");
     var content = $('#c'+parentId).val();
     if (!content) {
         alert("输入内容不能为空 ！")
         return;
     }
     var data = {
         content: content,
         parentId: parentId,
         type: 2
     }
     $.ajax({
         url: "/comment",
         contentType: "application/json",
         type: "POST",
         dataType: "json",
         data: JSON.stringify(data),
         success(response) {
             if (response.code == 200) {
                 $("#e"+parentId).html("")
                 collapseComment1(parentId)
                 $("#c"+parentId).val("")
                 $("html,body").animate({
                     scrollTop: $("#a"+parentId).eq(i).offset().top
                 }, 500);
             } else {
                 if (response.code = 2003) {
                     var isLogin = window.confirm(response.message);
                     if (isLogin) {
                         window.open("https://gitee.com/oauth/authorize?client_id=9cd8e853407fc6a52e6bc99f27e9d530a0c9bd9fcba10fccdd09d48d7c147d52&redirect_uri=http://localhost:8887/callback&scope=user_info&response_type=code");
                         window.localStorage.setItem("closed", true)
                     }

                 } else {
                     alert(response.message);
                 }
             }
         }
     })
 }

 function collapseComment(e) {
     var id = e.getAttribute("data");
     $("#a"+id).toggleClass("in")
     collapseComment1(id)
 }

 function collapseComment1(id) {
     if ($("#a" + id).hasClass("in")) {
         $.ajax({
             url: "/comment/"+id,
             type: "GET",
             contentType: "application/json",
             dataType: "json",
             success(response) {
                 $("#d" + id).children("span.like_count").text(response.data.length)
                 console.log(response.data.length)
                 $("#e"+id).html("")
                 response.data.forEach(function (item) {
                     console.log(item)
                     var str = "<div style=\"border-bottom: 1px solid #eeeeee;margin-top: 10px;\">\n" +
                         "    <div class=\"media-left\">\n" +
                         "        <a >\n" +
                         "            <img class=\"img_size media-object\" src=\"http://qseoqy0p2.hn-bkt.clouddn.com/zhugeliang.jpg\"\n" +
                         "                 alt=\"...\">\n" +
                         "        </a>\n" +
                         "    </div>\n" +
                         "    <div class=\"media-body\">\n" +
                         "        <span style=\"color: #888 !important;\"  class=\"media-heading avator_padding\" >"+item.user.name+"</span>\n" +
                         "        <p style=\"font-size: 16px;line-height: 20px;width: 450px;\" >"+item.content+"</p>\n" +
                         "        <div>\n" +
                         "            <div class=\"fl\" style=\"display: flex;margin-bottom: 7px\">\n" +
                         "            </div>\n" +
                         "            <div style=\"color: #888 !important;\" class=\"fr\"><span>"+moment(item.gmtCreate).format("YYYY-MM-DD hh:mm:ss")+"</span></div>\n" +
                         "        </div>\n" +
                         "    </div>\n" +
                         "</div>"
                     $("#e"+id).append(str);
                 })
             }
         })
     }

 }

